{extend name="public/base"/}
{block name="body"}
<div class="main-box no-header clearfix">
	<header class="main-box-header clearfix">
		<div class="pull-left">
			<h2>{$meta_title}（{$count}）</h2>
		</div>
		<div class="pull-right">

			 <button class="btn  btn-primary ajax-post" target-form="ids" url="{:url('copy')}">复 制</button>
			 <button class="btn  btn-primary "  data-toggle="modal" data-target="#myModal" >粘 贴</button>

			{notempty name="$Think.get.category"}	<button class="btn btn-success list_sort" url="{:url('sort','','')}">排序</button>{/notempty}
		</div>
	</header>
	<div class="main-box-body clearfix">
		<div class="row">
					<form method="get" id="formselect">
						<div class="col-sm-12 col-md-4 col-lg-3">
					<select name="category" id="category" class="form-control">
					<option value="">55全部分类</option>
					{volist name="catlist" id="vo"}
					<option value="{$key}"  {eq name="key" value="$Think.get.category"}selected{/eq} >{$vo}</option>
					{/volist}
					</select>
						</div>
					</form>
				</div>
				<script>
				$(function(){
					$('[name="category"]').change(function(){
							$('#formselect').submit();
					})
				})
				</script>

		<div class="table-responsive">
      <table class="table table-striped table-hover">
        <thead>
          <tr>
            <th width="30"><input class="checkbox check-all" type="checkbox"></th>
            <th width="60">ID</th>
            <th>商品图片</th>
            <th>标题</th>
            <th>分类</th>
            <th>商家</th>
            <th>描述</th>
            <th>更新时间</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          {volist name="list" id="item"}
          <tr>
            <td><input class="ids row-selected" type="checkbox" name="id[]" value="{$item['id']}"></td>
            <td>{$item['id']}</td>
            <td><img src="{$item['cover_id']|get_cover='path','96x50'}" width="96" height="50" /></td>
            <td>{$item['good_name']} <br /><br />
											{volist name="$item['goodsrule']" id="vo" }
													<p>规格：{$vo[rule_name]} 价格：{$vo[rule_price]}元 库存：{$vo[stock] >10 ? $vo[stock] : $vo[stock].'<span style="font-size: 16px;color: red;">(库存不足！)</span>'} 重量：{$vo[weight]}/斤 </p>
											{/volist}
						</td>
            <td>{$item['cat_id']|get_table_field="id","cat_name","goodscat"}</td>
            <td>{$item['shop_id']|get_table_field="id","shopname","goodshops"}</td>
						<td>{$item['good_desc']|msubstr=###,0,10}</td>
						<td >
							{$item.update_time}
						</td>
            <td>
							<a href="{:url('updateFieldById', ['id'=>$item['id'], 'field'=>'sort', 'value'=> '0'])}" class="ajax-get">刷新</a>
              <a href="{:url('edit',array('id'=>$item['id']))}">编辑</a>
							<a href="{:url('editStatus',array('id'=>$item['id'], 'status'=>-1))}" class="confirm ajax-get">下架</a>
              <a href="{:url('del',array('id'=>$item['id']))}" class="confirm ajax-get">删除</a>
            </td>
          </tr>
          {/volist}
        </tbody>
      </table>
			{$list->render()}
		</div>
	</div>
</div>

<!-- Modal -->
<div class="modal fade "  id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">粘贴的分类</h4>
      </div>
      <form class="form-horizontal" action="{:url('paste')}" method="post">
        <select name="cat_id" style="    margin: 30px auto;display: block;padding: 10px;">
					{volist name="catlist" id="vo"}
        		<option value="{$key}">{$vo}</option>
					{/volist}
        </select>
        <div class="modal-footer">
          <button type="submit" class="btn btn-primary submit-btn ajax-post"  target-form="form-horizontal">粘贴</button>
        </div>
      </form>
    </div>
  </div>
</div>
{/block}

{block name="script"}

<script type="text/javascript">
$(function() {
	//点击排序
	$('.list_sort').click(function(){
		var url = $(this).attr('url');
		var ids = $('.ids:checked');
		var param = '';
		if(ids.length > 0){
			var str = new Array();
			ids.each(function(){
				str.push($(this).val());
			});
			param = str.join(',');
		}

		if(url != undefined && url != ''){
			window.location.href = url +'/category/'+"{$Think.get.category}"+ '/ids/' + param;
		}
	});

});
</script>
{/block}
